/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.reporting;

import TimeRecording.tables.Employee;
import java.awt.Image;
import java.util.Date;

/**
 *
 * @author david
 */
public class AbsenceIconProvider extends CalendarIconProvider {

    private static boolean imagesLoaded = false;
    
    protected static Image holidayAmSickPmIcon;
    protected static Image sickAmHolidayPmIcon;

    private SicknessIconProvider sicknessIconProvider;
    private HolidayIconProvider holidayIconProvider;

    public AbsenceIconProvider() {

        super();

        sicknessIconProvider = new SicknessIconProvider();
        holidayIconProvider = new HolidayIconProvider();

        if (!imagesLoaded) {
            holidayAmSickPmIcon = loadImage("HolidayAmSickPm");
            sickAmHolidayPmIcon = loadImage("SickAmHolidayPm");
            imagesLoaded = true;
        }
    }

    public Image getIcon(Employee employee, Date date) {

        // Reconcile competing holiday and sickness.  In reallity, sickness and
        // holiday records should never coincide; if they do then the following
        // code gives precedence to the sicknes record.  Perhaps it could use
        // the colour ping to indicate that there is a clash?

        Image sicknessIcon = sicknessIconProvider.getIcon(employee, date);
        Image holidayIcon = holidayIconProvider.getIcon(employee, date);

        // If no sickness then defer to holiday icon
        if (sicknessIcon == CalendarIconProvider.presentIcon) {
            return holidayIcon;

        // If no holiday then defer to sickness icon
        } else if (holidayIcon == presentIcon) {
            return sicknessIcon;

        // If 100% sickness then just bulldoze it through
        } else if (sicknessIcon == SicknessIconProvider.sickIcon) {
            return sicknessIcon;

        // If AM sickness then see how it interacts with any holiday
        } else if (sicknessIcon == SicknessIconProvider.sickAmIcon) {
            if (holidayIcon == HolidayIconProvider.holidayPmIcon ||
                    holidayIcon == HolidayIconProvider.holidayIcon) {
                return sickAmHolidayPmIcon;
            } else {
                return SicknessIconProvider.sickAmIcon;
            }

        // If PM sickness then see how it interacts with any holiday
        } else {
            if (holidayIcon == HolidayIconProvider.holidayAmIcon ||
                    holidayIcon == HolidayIconProvider.holidayIcon) {
                return holidayAmSickPmIcon;
            } else {
                return SicknessIconProvider.sickPmIcon;
            }
        }
    }
}